﻿using System;
using System.Text.RegularExpressions;
using System.Windows.Input;
using Microsoft.Phone.Controls.Maps.Platform;

namespace Studentpartners.Sightseeing.ViewModels
{
    public class SightViewModel : ViewModelBase
    {
        public int Id { get; set; }

        public String Title { get; set; }
        public String Short { get
        {
            var retstr = Regex.Replace(Description, "<[^>]+?>", string.Empty);
            return (retstr.Length > 128) ? retstr.Substring(0, 128) : retstr;
        } }

        public String Description { get; set; }

        public Double Latitude { get; set; }
        public Double Longitude { get; set; }

        public ICommand NavigateTo { get { return new NavigationCommand(new Uri("/SightPage.xaml?id=" + Id, UriKind.Relative)); } }
        public ICommand CenterMap
        {
            get
            {
                return new RelayCommand((o) =>
                {
                    var page = App.MapsPage;
                    if (null != page)
                    {
                        page.SetMapPosition(new Location() { Latitude = this.Latitude, Longitude = this.Longitude });
                    }
                });
            }
        }
    }
}
